package se.zens.demo.wsapp;

import javax.xml.ws.Endpoint;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import se.zens.common.exception.ConfigurationException;
import se.zens.demo.wsapp.configuration.WSAppConfiguration;
import se.zens.demo.wsapp.configuration.WSConfiguration;

/**
 * WSApp is a webservice application used for automation testing demo
 *
 */
public class WSApp 
{
	private static Logger log = LogManager.getLogger(WSApp.class);
	
	private WSAppConfiguration config;
	
	public WSApp(WSAppConfiguration config)
	{
		this.config = config;
	}
    public static void main( String[] args )
    {
        try
		{
			WSApp wsApp = new WSApp(new WSAppConfiguration("wsapp"));
			wsApp.publishWebservices();
			
		} catch (ConfigurationException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }

	private void publishWebservices() throws ClassNotFoundException, InstantiationException, IllegalAccessException  
	{
		for(WSConfiguration wsConfig : config.getWebserviceConf() )
		{
			Class impl = this.getClass().getClassLoader().loadClass("se.zens.demo.wsapp.implementation." + wsConfig.getImplementationClass());
			
			Endpoint.publish(wsConfig.getPublishURL(), impl.newInstance());
		}	
		
	}
    
    
}
